﻿using Octokit;

Console.WriteLine("Hello, World!");
var gitHubClient = new GitHubClient(new ProductHeaderValue("MyCoolApp"));
gitHubClient.Credentials = new Credentials("Your Github Token");

var (owner, repoName, filePath, branch) = ("Your Github Owner", "Your Repo", "Your File Path", "main");

// 图片转base64上传到Github
string imagePath = @"C:\Users\starc\Desktop\test.png";
string base64String = GetImageBase64String(imagePath);

var result = await gitHubClient.Repository.Content.CreateFile(
     owner, repoName, filePath,
     new CreateFileRequest($"First commit for {filePath}", base64String, branch, false));

static string GetImageBase64String(string imgPath)
{
    byte[] imageBytes = System.IO.File.ReadAllBytes(imgPath);
    return Convert.ToBase64String(imageBytes);
}